package com;

import java.util.concurrent.atomic.LongAdder;

/**
 * @author zhangzhanheng
 * @date 2020/12/22 22:20
 */
public class zzh {
    //static int sum = 0;
//    static AtomicInteger sum = new AtomicInteger();
    static LongAdder sum = new LongAdder();

    public static void main(String[] args) throws Exception {

        int num = 16;

        Thread[] threads = new Thread[num];

        long start = System.currentTimeMillis();

        for (int i = 0; i < num; i++) {
            threads[i] = new Thread(() -> {
                for (int j = 0; j < 10_0000_0000; j++) {
//                    sum.incrementAndGet();
                    sum.increment();
                }
            });
            threads[i].start();
        }

        for (int i = 0; i < num; i++) {
            threads[i].join();
        }

        long end = System.currentTimeMillis();
        System.out.println(sum.longValue() + ",dura:" + (end - start));
    }

}
